#include "menu.h"

Menu::Menu() 
{

}

/*-------------------------------------------------------------------------------------------------------------*/
Menu::~Menu() 
{

}

/*-------------------------------------------------------------------------------------------------------------*/
bool Menu::Initialize() 
{

	// Set first option
	m_iOptionSelected = 0;

	for (int i=0; i < MENU_OPTIONS_COUNT; i++) 
	{
		if (!m_option[i].LoadIni("data/graphics/menu.spr"))
		{
			return false;
		}

		m_option[i].SetFrame(i*2);

		if (i>0) 
		{	
			m_option[i].SetPosX(m_option[i-1].GetPosX());
			m_option[i].SetPosY(m_option[i-1].GetPosY() - m_option[i-1].GetHeight() - 5);
		} 
		else 
		{
			m_option[i].SetPos(MENU_START_POS_X,MENU_START_POS_Y);
		}
	}
	m_iStage = MENU_STAGE_NONE;

	return true;
}

/*-------------------------------------------------------------------------------------------------------------*/
void Menu::Update(float fDt) 
{
	if (KeyDown(DIK_DOWN)) 
	{
		m_iOptionSelected++;

		if (m_iOptionSelected >= MENU_OPTIONS_COUNT) 
		{
			m_iOptionSelected = 0;
		}
	} 

	else if (KeyDown(DIK_UP)) 
	{
		m_iOptionSelected--;

		if (m_iOptionSelected < 0) 
		{
			m_iOptionSelected = MENU_OPTIONS_COUNT-1;
		}
	}

	if (KeyDown(DIK_RETURN))
	{
		m_iStage = m_iOptionSelected+1;
	}

	for (int i=0; i < MENU_OPTIONS_COUNT; i++) 
	{
		m_option[i].SetFrame(i*2);

		m_option[i].Update(fDt);
	}

	m_option[m_iOptionSelected].SetFrame(m_iOptionSelected*2+1);
}

/*-------------------------------------------------------------------------------------------------------------*/
void Menu::Draw() 
{
	for (int i=0; i < MENU_OPTIONS_COUNT; i++) 
	{
		m_option[i].Draw();
	}
}

